﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'PRC_TB_ALERTS_TASKS_HISTORY_EXCED_TASK_SE')
	BEGIN
		DROP  Procedure  dbo.PRC_TB_ALERTS_TASKS_HISTORY_EXCED_TASK_SE
	END

GO

CREATE Procedure dbo.PRC_TB_ALERTS_TASKS_HISTORY_EXCED_TASK_SE
	(
		@TA_ID int
	)

AS

select
	TA_ID,
	TA_USER_ID,
	TA_NAME,
	TA_STATE,
	TA_SLEEP_DATE,
	TA_TYPE,
	TAT_ID,
	TAT_ALERT_ID,
	TAT_SCHEDULE_START_FROM,
	TAT_SCHEDULE_START_TO,
	TAT_SCHEDULE_END_FROM,
	TAT_SCHEDULE_END_TO,
	TATH_ALERT_TASK_ID,
	TATH_WEEKEND,
	TATH_HOLIDAY,
	TATH_HOUR_DAY,
	TATH_PERCENT
from TB_ALERTS
	inner join TB_ALERTS_TASKS
		on TAT_ALERT_ID = TA_ID
	inner join TB_ALERTS_TASKS_HISTORY_EXCED_TASK
		on TATH_ALERT_TASK_ID = TAT_ID
where TA_ID = @TA_ID
order by TA_NAME

GO

GRANT EXEC ON dbo.PRC_TB_ALERTS_TASKS_HISTORY_EXCED_TASK_SE TO PUBLIC

GO

